import { concat } from "lodash"

export default {
    setFilms(state, filmsList) {
        return {
            ...state,
            filmsList
        }
    },
    changFlag1(state, data) {
        return {
            ...state,
            flag: data.flag,
            left: data.left
        }
    },
    changFlag2(state, data) {
        return {
            ...state,
            flag: data.flag,
            left: data.left
        }
    },
    filmLoginUser(state, data) {
        return {
            ...state,
            username: data,
        }
    },
    filmLoginPwd(state, data) {
        return {
            ...state,
            password: data,
        }
    },
    // 获取详情页数据
    getFilmDetail(state, data) {
        return {
            ...state,
            detailObj: data,
        }
    },
    // 添加评论
    pinglun(state, data) {
        return {
            ...state,
            ping: {
                id: data.id,
                neirong: data.neirong
            }
        }
    },
    getPing(state, data) {
        let p = state.pinglun.filter(item => item.id === data.id)
        console.log(p);
        if (p.length === 0) {
            return {
                ...state,
                pinglun: [...state.pinglun, data]
            }
        } else {
            alert('一个用户只能评论一次')
            return state
        }
    },
    // 添加记录
    addjilu(state, data) {
        console.log(data);
        if (state.jilu === null) {
            return {
                ...state,
                jilu: [data]
            }
        }else{
            return {
                ...state,
                jilu: concat(state.jilu,[data])
            }
        }

    }
}